package com.example.vo;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class SysResult implements Serializable {

    private static final long serialVersionUID = 3822346245873389717L;

    public static final int STATUS_OK = 200;
    public static final int STATUS_FAILED = 400;
    public static final int STATUS_PARAM_ERROR = 401;
    public static final int STATUS_SERVER_ERROR = 500;

    private static final Map<Integer, String> DEFAULT_MESSAGES;

    static {
        DEFAULT_MESSAGES = new HashMap<>();
        DEFAULT_MESSAGES.put(STATUS_OK, "OK");
        DEFAULT_MESSAGES.put(STATUS_FAILED, "操作失败");
        DEFAULT_MESSAGES.put(STATUS_PARAM_ERROR, "参数错误");
        DEFAULT_MESSAGES.put(STATUS_SERVER_ERROR, "网络错误");
    }

    private Integer status;
    private String msg;

    static {

    }

    public SysResult() {
    }

    public SysResult(Integer status) {
        this(status, DEFAULT_MESSAGES.get(status));
    }

    public SysResult(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }


    public static SysResult ok() {
        return new SysResult(STATUS_OK);
    }

    public static SysResult build(Integer status) {
        return new SysResult(status);
    }

    public static SysResult build(Integer status, String msg) {
        return new SysResult(status, msg);
    }


    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        return "SysResult{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                '}';
    }

}
